import { request } from './request';

export function getCateList(cateId, sel) {
  return request({
    url: `categories/${cateId}/attributes`,
    params: {
      sel
    }
  });
}

export function addCateParams(cateId, attr_name, attr_sel) {
  return request({
    url: `categories/${cateId}/attributes`,
    method: 'post',
    data: {
      attr_name,
      attr_sel
    }
  });
}

export function queryParams(cateId, attrId, attr_sel) {
  return request({
    url: `categories/${cateId}/attributes/${attrId}`,
    params: {
      attr_sel
    }
  });
}

export function editSubmitParams(cateId, editForm) {
  return request({
    url: `categories/${cateId}/attributes/${editForm.attr_id}`,
    method: 'put',
    data: {
      attr_name: editForm.attr_name,
      attr_sel: editForm.attr_sel,
    }
  });
}

export function deleteParams(cateId, attr_id) {
  return request({
    url: `categories/${cateId}/attributes/${attr_id}`,
    method: 'delete'
  });
}

export function submitParams(cateId, editForm) {
  return request({
    url: `categories/${cateId}/attributes/${editForm.attr_id}`,
    method: 'put',
    data: {
      attr_name: editForm.attr_name,
      attr_sel: editForm.attr_sel,
      attr_vals: editForm.attr_vals.join(' ')
    }
  });
}